/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ivanbiz.welcome;

import com.ivanbiz.departement.DepartementAction;
import com.ivanbiz.departement.DepartementService;
import com.ivanbiz.injection.CallCtx;
import com.ivanbiz.properties.SISBeanConstants;
import com.ivanbiz.properties.SISConstants;
import com.ivanbiz.properties.SISScreenConstants;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.HttpSession;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.util.MessageResources;

/**
 *
 * @author Ivan
 */
public class WelcomeAction extends org.apache.struts.action.Action {

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) {
        ActionMessages actionMessages = new ActionMessages();
        DepartementService departementService = (DepartementService) CallCtx.getContext(request).getBean(SISBeanConstants.DEPARTEMENT_SERVICE);
        HttpSession session = request.getSession(true);
        MessageResources messageResources = getResources(request);
        try {
            List listDepartement = departementService.loadAll();
            session.setAttribute(SISConstants.LIST_DEPARTEMENT, listDepartement);
            session.setAttribute(SISConstants.BUTTON_ADD, messageResources.getMessage(SISConstants.LABEL_ADD));
            session.setAttribute(SISConstants.BUTTON_SAVE, messageResources.getMessage(SISConstants.LABEL_SAVE));
            session.setAttribute(SISConstants.BUTTON_UPDATE, messageResources.getMessage(SISConstants.LABEL_UPDATE));
            session.setAttribute(SISConstants.BUTTON_LOGIN, messageResources.getMessage(SISConstants.LABEL_LOGIN));
            session.setAttribute(SISConstants.BUTTON_BACK, messageResources.getMessage(SISConstants.LABEL_BACK));
            session.setAttribute(SISConstants.BUTTON_EDIT, messageResources.getMessage(SISConstants.LABEL_EDIT));
            session.setAttribute(SISConstants.BUTTON_NEW, messageResources.getMessage(SISConstants.LABEL_NEW));
        } catch (Exception ex) {
            Logger.getLogger(DepartementAction.class.getName()).log(Level.SEVERE, null, ex);
            actionMessages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(SISConstants.GLOBAL_EXCEPTION));
            saveMessages(request, actionMessages);
            return new ActionForward(mapping.getInput());
        }
        return mapping.findForward(SISScreenConstants.SUCCESS);
    }
}
